//
//  BaseNavBarView.m
//  project-demo-oc
//
//  Created by 赵隆杰 on 2021/6/1.
//

#import "BaseNavBarView.h"

@implementation BaseNavBarView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self configView];
    }
    return self;
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    [self configView];
}

- (void)configView {
    self.backgroundColor = [UIColor whiteColor];
    
    
    UIView *navView = [UIView new];
    [self addSubview:navView];
    [navView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.bottom.equalTo(self).offset(1);
        make.height.mas_equalTo(44);
    }];
    self.navView = navView;
    
    UILabel *centerLabel = [UILabel new];
    centerLabel.font = [UIFont boldSystemFontOfSize:18];
    centerLabel.textColor = [UIColor blackColor];
    centerLabel.textAlignment = NSTextAlignmentCenter;
    [navView addSubview:centerLabel];
    [centerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(navView);
    }];
    self.centerLabel = centerLabel;
    
    UIButton *backBtn = [[UIButton alloc] init];
    [backBtn setTitle:@"返回" forState:UIControlStateNormal];
    [backBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    backBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:backBtn];
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(navView);
        make.width.mas_equalTo(68);
    }];
    self.backBtn = backBtn;
    
    UIButton *rightBtn = [UIButton new];
    [rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [backBtn addTarget:self action:@selector(rightClick) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:rightBtn];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.equalTo(navView);
        make.width.mas_equalTo(68);
    }];
    rightBtn.hidden = YES;
    self.rightBtn = rightBtn;
    
    UILabel *line = [[UILabel alloc] init];
    line.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self);
        make.height.mas_equalTo(1);
    }];
}

- (void)backClick {
    if (self.delegate && [self.delegate respondsToSelector:@selector(backBtnBlock)]) {
        [self.delegate backBtnBlock];
    }
}

- (void)rightClick {
    if (self.delegate && [self.delegate respondsToSelector:@selector(rightBtnBlock)]) {
        [self.delegate rightBtnBlock];
    }
}

@end
